import Vue from 'vue'
import Router from 'vue-router'
import { constantRouterMap } from '@/config/router.config'

// //update-begin-author:taoyan date:20191011 for:TASK #3214 【优化】访问online功能测试 浏览器控制台抛出异常
// try {
//   const originalPush = Router.prototype.push
//   Router.prototype.push = function push(location) {
//     return originalPush.call(this, location).catch(err => err)
//   }
// } catch (e) {
// }
// //update-end-author:taoyan date:20191011 for:TASK #3214 【优化】访问online功能测试 浏览器控制台抛出异常

const routes = [
  {
    path: '/',
    name: 'IndexPage',
    component: () => import('../views/index/IndexPage.vue'),
    meta: { title: '申请分享员' },
  },
]

Vue.use(Router)

export default new Router({
  mode: 'history',
  base: process.env.BASE_URL,
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRouterMap
})


// import Vue from 'vue'
// import Router from 'vue-router'

// Vue.use(Router)

// const routes = [
//   {
//     path: '/',
//     name: 'IndexPage',
//     component: () => import('../views/index/IndexPage.vue'),
//     meta: { title: '申请分享员' },
//   },
// ]

// const router = new Router({
//   mode: 'history',
//   routes,
//   scrollBehavior(to, from, savedPosition) {
//     if (savedPosition) {
//       return savedPosition
//     } else {
//       return { x: 0, y: 0 }
//     }
//   },
// })

// // 设置页面标题
// router.beforeEach((to, from, next) => {
//   document.title = to.meta.title || ''
//   let url = window.location.href
//   const extensionRegex = /\.txt$/ // 正则表达式匹配.txt结尾
//   if (!extensionRegex.test(url)) {
//     next()
//   } else {
//     window.location.href = url
//   }
// })

// export default router


